<template>
	<view>
		<view style="padding: 20upx;">
			<view @tap="toHome(item)" v-for="(item,key) in teams.list" :key="key" style="margin-bottom: 20upx;padding: 20upx;border-radius: 15upx;background-color: white;display: flex;">
				<image style="width: 70upx;height: 70upx;border-radius: 35upx;margin: 20upx;" src="../../static/5c331ec8ad0767c2f78171ffa13c2ee0.jpg"></image>
				<view style="flex: 1;">
					<view>
						<text style="font-weight: bold;line-height: 60upx;">{{item.teamName}}</text>
						<text style="float: right;font-size: 25upx;color: #FF387B;">距离1m</text>
					</view>
					<view style="font-size: 25upx;color: #666666;line-height: 60upx;">{{item.address}}</view>
					<view style="font-size: 25upx;color: #999999;line-height: 60upx;">自提点联系人：{{item.contacts}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				teams: {
					noData: true,
					pageNum: 1,
					pageSize: 10,
					list: []
				},
			}
		},
		onLoad() {
			this.getLocation()
		},
		methods: {
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: res => {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						this.getNearest(res.longitude, res.latitude)
					},
					fail: (err) => {
						console.log(err)
						uni.showToast({
							title: '请检查手机定位功能是否打开',
							icon: 'none'
						});
					}
				});
			},
			getNearest(longitude, latitude) {
				console.log(longitude,latitude)
				uni.request({
					url: this.apiUrl + "/client/team/list",
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						longitude:longitude, 
						latitude:latitude,
						pageNum: this.teams.pageNum,
						pageSize: this.teams.pageSize
					},
					success: (res) => {
						const result = res.data;
						console.log(result)
						if (result.code === 200) {
							const data = result.data.list;

							if (this.teams.pageNum == 1) {
								this.teams.list = data;
							} else {
								for (var i = 0; i < data.length; i++) {
									this.teams.list.push(data[i])
								}
							}
							console.log(this.teams)
						} else {
							uni.showToast({
								title: result.msg,
								icon: "none"
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.errMsg,
							icon: "none"
						});
					}
				})
			},
			toHome(item) {
				uni.setStorageSync('current_team',JSON.stringify(item))
				uni.switchTab({
					url: '../tabbar/home/home'
				})
			}
		}
	}
</script>

<style>

</style>
